package com.huluobo.a2111douyindemo.adapter;

import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.view.View;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.huluobo.a2111douyindemo.R;
import com.huluobo.a2111douyindemo.utils.ImageLoader;
import com.huluobo.mvvm_base.mvvm.bean.VideoBeanResult;
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;

import java.util.List;

/**
 * Created by LC on 2024/2/28.
 */
public class VideoAdapter extends BaseQuickAdapter<VideoBeanResult.VideoBean, BaseViewHolder> {
    public VideoAdapter(@Nullable List<VideoBeanResult.VideoBean> data) {
        super(R.layout.item_video, data);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, VideoBeanResult.VideoBean videoBean) {
        StandardGSYVideoPlayer player = baseViewHolder.getView(R.id.item_video_gsy_player);
        //获取播放器上的返回按钮,隐藏
        player.getBackButton().setVisibility(View.GONE);
        //播放器添加播放地址 cacheWithPlay 边播放边缓存
        player.setUp(videoBean.getVideopath(), true, "");

        //左下角区域信息赋值
        //地址
        baseViewHolder.setText(R.id.item_video_address_tv, videoBean.getAddress());
        //用户名
        baseViewHolder.setText(R.id.item_video_username_tv, videoBean.getAuthname());
        //描述
        baseViewHolder.setText(R.id.item_video_caption_tv, videoBean.getCaption());
        //原创
        baseViewHolder.setText(R.id.item_video_pao_tv, videoBean.getAuthname() + "的原创作品");

        //右下方区域赋值
        //头像
        ImageView headView = baseViewHolder.getView(R.id.item_video_header_iv);
        ImageLoader.getInstance().loadCircleImage(getContext(), videoBean.getHeadpath(), headView);
        //关注状态,0代表未关注,展示+号,1代表已关注,隐藏+号
        if (videoBean.getGuanzhu() == 0) {
            baseViewHolder.getView(R.id.item_video_add_iv).setVisibility(View.VISIBLE);
        } else {
            baseViewHolder.getView(R.id.item_video_add_iv).setVisibility(View.GONE);
        }
        //点赞状态,0代表未点赞(白心),1代表点赞(红心)
        if (videoBean.getDianzan() == 0) {
            baseViewHolder.setImageResource(R.id.item_video_like_iv, R.drawable.ic_xihuan);
        } else {
            baseViewHolder.setImageResource(R.id.item_video_like_iv, R.drawable.ic_xihuanred);
        }
        //点赞数量
        int likeCount = videoBean.getLike_count();
        baseViewHolder.setText(R.id.item_video_like_count_tv, likeCount < 10000 ? String.valueOf(likeCount) :
                likeCount / 10000 + "W");
        //评论数量
        baseViewHolder.setText(R.id.item_video_comment_count_tv, "5.5W");
        //收藏数量
        baseViewHolder.setText(R.id.item_video_follow_count_tv, "3.2W");
        //分享数量
        baseViewHolder.setText(R.id.item_video_share_count_tv, "2.2W");

        //碟片动画
        ImageView videoPlayer = baseViewHolder.getView(R.id.item_video_music_player_iv);
        ImageLoader.getInstance().loadCircleImage(getContext(), videoBean.getHeadpath(), videoPlayer);

        ObjectAnimator animator = ObjectAnimator.ofFloat(videoPlayer, "Rotation", 0, 360);
        animator.setDuration(3000);
        animator.setRepeatCount(ValueAnimator.INFINITE);//循环次数,INFINITE 无限循环
        animator.setInterpolator(new LinearInterpolator());
        animator.start();
    }
}
